package org.csu.small.controller.front;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.csu.small.common.Constant;
import org.csu.small.common.UniformResponse;
import org.csu.small.handler.RestExceptionHandler;
import org.csu.small.common.UniformResponse;
import org.csu.small.entity.Product;

import org.csu.small.service.IProductService;
import org.csu.small.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/product/")
@Api(value = "API - FProductController", description = "前台商品接口详情")
public class FProductController {

    @Autowired
    private IProductService productService;


    @Autowired
    private RestExceptionHandler restExceptionHandler;


    @GetMapping("detail")
    @ResponseBody
    @ApiOperation(value = "商品详情")
    public UniformResponse<ProductVO> detail(Integer productId){
        UniformResponse<ProductVO> response = productService.detail(productId, Constant.Role.CUSTOMER);

        return response;
    }

    @GetMapping("list")
    @ResponseBody
    @ApiOperation(value = "商品查询")
    public UniformResponse<Object> getProductList(
            @RequestParam(name = "categoryId", required = false) Integer categoryId,
            @RequestParam(name = "keyword", required = false) String keyword,
            @RequestParam(name = "pageNum", defaultValue = "1") int pageNum,
            @RequestParam(name = "pageSize", defaultValue = "5") int pageSize,
            @RequestParam(name = "orderBy", defaultValue = "") String orderBy){
        UniformResponse<Object> response = productService.getProductList(categoryId, keyword, pageNum, pageSize, orderBy, Constant.Role.CUSTOMER);

        return response;
    }

    @GetMapping("index_product")
    @ResponseBody
    @ApiOperation(value = "主页商品获取")
    public UniformResponse<Object> getIndexProductList(){
        UniformResponse<Object> response = productService.getIndexProductList();
        return response;
    }
}
